home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jbindtext.tcl < prev    next >
Encoding:
Text File  |  1995-02-09  |  5.9 KB  |  183 lines

  1. # jbindtext.tcl - support for Text bindings
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5.  
  6. ######################################################################
  7. ######################################################################
  8. # NOTE : this library is heavily dependent on jtext.tcl as a wrapper
  9. # around the widget commands
  10. ######################################################################
  11. ######################################################################
  12.  
  13.  
  14. ######################################################################
  15. # j:selection_if_any - return selection if it exists, else {}
  16. #   this is from kjx@comp.vuw.ac.nz (R. James Noble)
  17. #   defined elsewhere, but copied here so the bindings libraries
  18. #   don't depend on jtkutils
  19. ######################################################################
  20.  
  21. if {[info procs j:selection_if_any] == {}} {
  22.   proc j:selection_if_any {} {
  23.     if {[catch {selection get} s]} {return ""} {return $s}
  24.   }
  25. }
  26.  
  27. ######################################################################
  28. ####
  29. ###  GENERAL BINDING ROUTINES
  30. ####
  31. ######################################################################
  32.  
  33. ######################################################################
  34. # j:tb:init - initialise info for bindings
  35. ######################################################################
  36.  
  37. proc j:tb:init { {t Text} } {
  38.   global J_PREFS env
  39.   if {! [info exists J_PREFS(typeover)]} {set J_PREFS(typeover) 1}
  40.   switch -exact $J_PREFS(bindings) {
  41.     basic {
  42.       j:tb:basic_init $t
  43.     }
  44.     emacs {
  45.       j:tb:emacs_init $t
  46.     }
  47.     edt {
  48.       j:tb:edt_init $t
  49.     }
  50.     vi {
  51.       j:tb:vi_init $t
  52.     }
  53.   }
  54.  
  55.   # read in user's supplementary text bindings
  56.   j:source_config textbindings.tcl
  57. }
  58.  
  59. ######################################################################
  60. # j:tb:no_op - do nothing
  61. ######################################################################
  62.  
  63. proc j:tb:no_op { args } {
  64.   return 0
  65. }
  66.  
  67. ######################################################################
  68. # j:tb:beep W - beep
  69. ######################################################################
  70.  
  71. proc j:tb:beep { W args } {
  72.   j:beep $W
  73.   return 0
  74. }
  75.  
  76. ######################################################################
  77. # j:tb:move W index - move, possibly clearing selection and resetting state
  78. ######################################################################
  79.  
  80. proc j:tb:move { W index } {
  81.   global J_PREFS
  82.   
  83.   if $J_PREFS(typeover) {
  84.     # clear current selection:
  85.     $W tag remove sel 1.0 end
  86.   }
  87.   j:text:move $W $index
  88. }
  89.  
  90. ######################################################################
  91. # j:tb:clear_selection W - clear the selection in widget W
  92. ######################################################################
  93.  
  94. proc j:tb:clear_selection { W args } {
  95.   $W tag remove sel 1.0 end
  96. }
  97.  
  98. ######################################################################
  99. # j:tb:select_all W - select all text in widget W
  100. ######################################################################
  101.  
  102. proc j:tb:select_all { W args } {
  103.   $W tag add sel 1.0 end
  104. }
  105.  
  106. ######################################################################
  107. # j:tb:is_bol W - return true if insert is at beginning of line
  108. #   from Achim Bohnet <ach@rosat.mpe-garching.mpg.de>
  109. ######################################################################
  110.  
  111. proc j:tb:is_bol { W } {
  112.   return [$W compare insert == "insert linestart"]
  113. }
  114.  
  115. ######################################################################
  116. # j:tb:is_eol W - return true if insert is at end of line
  117. #   from Achim Bohnet <ach@rosat.mpe-garching.mpg.de>
  118. ######################################################################
  119.  
  120. proc j:tb:is_eol { W } {
  121.   return [$W compare insert == "insert lineend"]
  122. }
  123.  
  124. ######################################################################
  125. # j:tb:is_first_line W - return true if insert is on top line
  126. ######################################################################
  127.  
  128. proc j:tb:is_first_line { W } {
  129.   return [$W compare "insert linestart" == 1.0]
  130. }
  131.  
  132. ######################################################################
  133. # j:tb:is_last_line W - return true if insert is on last line
  134. ######################################################################
  135.  
  136. proc j:tb:is_last_line { W } {
  137.   return [$W compare "insert lineend" == end]
  138. }
  139.  
  140. ######################################################################
  141. ######################################################################
  142. # ROUTINES TO SET UP TEXT BINDINGS
  143. ######################################################################
  144. ######################################################################
  145.  
  146. # j:tb:key_bind W - set up bindings to process keys
  147. proc j:tb:key_bind { W args } {
  148.   # get rid of a few default Tk bindings:
  149.   foreach binding {
  150.     <Control-Key-v> <Control-Key-d> <Control-Key-h> <Any-Key>
  151.     <Key-Delete> <Key-BackSpace> <Key-Return>
  152.   } {
  153.     bind $W $binding {}
  154.   }
  155.   # and create null bindings for modifiers, so they don't trigger commands:
  156.   foreach binding {
  157.     <Shift_L> <Shift_R> <Control_L> <Control_R> <Caps_Lock>
  158.     <Shift_Lock> <Meta_L> <Meta_R> <Alt_L> <Alt_R>
  159.   } {
  160.     bind $W $binding { }
  161.   }
  162.   bind $W <Key>            {j:tkb:process_key %W "" %K %A}
  163.   bind $W <Shift-Key>        {j:tkb:process_key %W "" %K %A}
  164.   bind $W <Control-Key>        {j:tkb:process_key %W Control %K %A}
  165.   
  166.   # Compose (Multi_key) key support:
  167.   bind $W <Multi_key>        { }
  168.   bind $W <Multi_key><Any-Key>    {j:tc:start_sequence %W %K %A}
  169.   bind $W <Multi_key><Any-Key><Any-Key> \
  170.                   {j:tc:finish_sequence %W %K %A}
  171.   bind $W <Multi_key><Any-KeyRelease><Any-Key> \
  172.                     {j:tc:start_sequence %W %K %A}
  173.   bind $W <Multi_key><Any-Key><Any-Key> \
  174.                   {j:tc:finish_sequence %W %K %A}
  175.   bind $W <Multi_key><Any-Key><Any-KeyRelease><Any-Key> \
  176.                   {j:tc:finish_sequence %W %K %A}
  177.   bind $W <Multi_key><Any-KeyRelease><Any-Key><Any-KeyRelease><Any-Key> \
  178.                   {j:tc:finish_sequence %W %K %A}
  179.  
  180. }
  181.  
  182.